package cc.uncarbon.module.appapi.service;

import cc.uncarbon.module.appapi.mapper.BannerMapper;
import cc.uncarbon.module.appapi.model.response.BannerBO;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yanrumiao.entity.BannerEntity;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.annotation.RCascade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
@Service
@Slf4j
public class BannerService {

    private final BannerMapper bannerMapper;
    public List<BannerBO> getList(Long storeId) {
        LambdaQueryWrapper<BannerEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BannerEntity::getStatus, 1);
        wrapper.orderByAsc(BannerEntity::getSort);
        List<BannerEntity> list = bannerMapper.selectList(wrapper);
        if (!list.isEmpty()) {
            List<BannerBO> listBo = new ArrayList<>(list.size());
            list.forEach(entity -> listBo.add(this.entity2BO(entity)));
            return listBo;
        }
        return new ArrayList<>();

    }

    private BannerBO entity2BO(BannerEntity entity) {
        if (entity == null) {
            return null;
        }
        BannerBO bo = new BannerBO();
        BeanUtil.copyProperties(entity, bo);
        return bo;
    }
}
